﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.GamerServices;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Box2D.XNA;

/// <Summary> 
/// CreateSession Calls CreateSession Screen
/// Join Session calls FindSession Screen
/// </Summary> 


namespace Imagine
{
    class MenuScreen : GameScreen
    {
        Squit box;
        SimpleSprite sprite;
        SimpleAnimatedSprite act1;
        SimplePhysicsSprite ground;
        SimplePhysicsSprite tile1;
        SimplePhysicsSprite tile2;
        SimplePhysicsSprite tile3;        

         public override bool Init(object extraData)
         {
             box = new Squit("look");
             act1 = new SimpleAnimatedSprite("look");
             //Create Ground
             ground = new SimplePhysicsSprite("ground");
             ground.PhysicsSprite.Position = new Vector2(0.0f + ground.PhysicsSprite.FrameSize.X/2, 450 - 32);
             ground.PhysicsSprite.Friction = 1.0f;             
             //ground.InitPhysics(ShapeType.eSHAPE_BOX);
             //ground.PhysicsSprite.Body.SetUserData("ground");
             LevelEditor.Instance().ReadTileMap(@"Content/Levels/0.txt");
           
             tile1 = new SimplePhysicsSprite("look");
             tile1.PhysicsSprite.Position = new Vector2(400,260);
             //tile1.InitPhysics(ShapeType.eSHAPE_BOX);

             TheWorld.Instance().Add(box, RenderLayers.eDefault);
             //TheWorld.Instance().Add(ground, RenderLayers.eDefault);             
             //TheWorld.Instance().Add(tile1, RenderLayers.eDefault);
             //TheWorld.Instance().Add(tile3, RenderLayers.eDefault);
             //TheWorld.Instance().Add(tile2, RenderLayers.eDefault);
             
             return true;

         }

         public override bool Draw(GameTime gameTime, SpriteBatch spriteBatch) 
         {
            // Engine.Instance().GraphicsDevice.Clear(Color.White);
             spriteBatch.DrawString(Engine.Instance().SpriteFont, " MenuScreen", new Vector2(0,0),Color.Chocolate);
             spriteBatch.DrawString(Engine.Instance().SpriteFont, " 1 = Create Session", new Vector2(200,200),Color.Chocolate);
             spriteBatch.DrawString(Engine.Instance().SpriteFont, " 2 = Join Session", new Vector2(200,230),Color.Chocolate);
             Vector2 mousePos = InputManager.Instance().GetMousePos();
             Vector2 boxPos = box.m_squit.Position;
             
             spriteBatch.DrawString(Engine.Instance().SpriteFont, mousePos.ToString(), new Vector2(400,0),Color.Chocolate);
             spriteBatch.DrawString(Engine.Instance().SpriteFont, boxPos.ToString(), new Vector2(700,0),Color.Chocolate);
             
             return true;
         }

         public override bool Update(GameTime gameTime) 
         {
             Engine.Instance().Camera.Position = new Vector3 (box.m_squit.Position,0.0f);

             if (InputManager.Instance().IsKeyDown(Keys.D1))
                 ScreenManager.Instance().SetScreen(ImagineScreens.eCreateSessionScreen, ScreenState.Dead, null);

             if (InputManager.Instance().IsKeyDown(Keys.D2))
                 ScreenManager.Instance().SetScreen(ImagineScreens.eFindSessionScreen, ScreenState.Active, null);

             //----------------------Camera Control-------------------------
              if (InputManager.Instance().IsKeyDown(Keys.Left))
                 Engine.Instance().Camera.Position += new Vector3(-5.0f,0.0f,0.0f);

             if (InputManager.Instance().IsKeyDown(Keys.Right))
                 Engine.Instance().Camera.Position += new Vector3(5.0f,0.0f,0.0f);

              if (InputManager.Instance().IsKeyDown(Keys.Up))
                 Engine.Instance().Camera.Position += new Vector3(0.0f,-5.0f,0.0f);

             if (InputManager.Instance().IsKeyDown(Keys.Down))
                 Engine.Instance().Camera.Position += new Vector3(0.0f,5.0f,0.0f);

             if (InputManager.Instance().IsKeyDown(Keys.Q))
                 Engine.Instance().Camera.Rotation += 0.04f;

             if (InputManager.Instance().IsKeyDown(Keys.E))
                 Engine.Instance().Camera.Rotation -= 0.04f;

             if (InputManager.Instance().IsKeyDown(Keys.PageUp))
                 Engine.Instance().Camera.ScaleX += 0.1f;

             if (InputManager.Instance().IsKeyDown(Keys.PageDown))
                 Engine.Instance().Camera.ScaleX -= 0.1f;
             //------------------------XXX------------------------------

             if (InputManager.Instance().IsKeyDown(Keys.Z))
             {}
                 //pspr.PhysicsBody.ApplyForce(new Vector2(5,5),pspr.Origin);
             if (InputManager.Instance().IsKeyDown(Keys.X))
             {}
                 //act2.Play();
             if (InputManager.Instance().IsKeyDown(Keys.C))
             {}
                 //act2.Stop();

             return true;
         }

         public override bool Release()
         {             

             return true;
         }
    }
}


